<template>
  <div class="app-container">

    <div class="operator-container">
      <div>

        审核状态：
        <el-select v-model="ulock" placeholder="请选择状态">
          <el-option v-for="item in ulockList" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
        <el-button type="primary" size="mini" :loading="listLoading" @click="showContent">查询</el-button>
      </div>
      <!-- <div>
        <el-button v-permission="['GET /admin/realprove/batchexamine']" class="filter-item" type="primary"  @click="batchPass">批量审核</el-button>
        <el-button v-permission="['GET /admin/realprove/batchnoexamine']" class="filter-item" type="danger"  @click="batchReject">批量驳回</el-button>
      </div> -->
    </div>

    <!-- 查询结果 -->
    <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" />
      <el-table-column align="center" label="id" prop="id" />
      <el-table-column align="center" label="游戏名称" prop="gameName" />
      <el-table-column align="center" label="介绍" prop="simpleText" />
      <el-table-column align="center" label="增加时间" prop="updateTime" />
      <el-table-column align="center" label="操作" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="primary" v-if="!scope.row.ulock" size="mini" @click="Pass(scope.row)">通过审核</el-button>
          <el-button type="danger" v-if="scope.row.ulock" size="mini" @click="Reject(scope.row)">驳回审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="prev, pager, next,sizes,total" :total='total' @current-change='current_change' @size-change='size_change' style="text-align: center; margin-top: 60px;" :page-sizes="[10, 50, 100, 1000]"></el-pagination>
  </div>
</template>

<script>
import api from '@/api/gameBox'
import storage from '@/api/storage'
import { getToken } from '@/utils/auth'

export default {
  name: 'GMaudit',

  data() {
    return {
      ulock: 0,
      ulockList: [
        { id: 0, name: '未审核' },
        { id: 1, name: '已审核' }
      ],
      listTrue: [],
      listfalse: [],
      list: [],
      total: 0,
      listLoading: false,
      listQuery: {
        page: 1,
        limit: 20,
        title: undefined,
        content: undefined,
        sort: 'add_time',
        order: 'desc'
      }
    }
  },
  computed: {
    headers() {
      return {
        'X-Hyxxkj-Admin-Token': getToken()
      }
    }
  },
  created() {},
  mounted() {
    this.getList()
  },
  methods: {
    handleSelectionChange(e) {
      // 选中
    },
    getList() {
      this.listLoading = true
      api
        .list({
          limit: this.listQuery.limit,
          page: this.listQuery.page
        })
        .then((res) => {
          this.listLoading = false
          var resDate = res.data.data.list
          this.listTrue = []
          this.listfalse = []
          resDate.map((res) => {
            if (res.ulock) {
              this.listTrue.push(res)
            } else {
              this.listfalse.push(res)
            }
          })
          this.showContent()
        })
        .catch((res) => {
          this.listLoading = false
        })
    },
    showContent() {
      // 查询
      if (this.ulock) {
        this.list = this.listTrue
      } else {
        this.list = this.listfalse
      }

      this.total = this.list.length
    },
    current_change(e) {
      this.page = e
      this.getList()
    },
    size_change(e) {
      this.limit = e
      this.getList()
    },
    Pass(e) {
      // 通过
      api
        .ulock({
          id: e.id
        })
        .then((res) => {
          console.log(res.data)
          if (res.data.errno == 0) {
            this.getList()
            this.$message.success('审核成功')
          } else {
            this.$message.error('审核失败')
          }
        })
        .catch((err) => {})
    },
    Reject(e) {
      // 驳回
      api
        .ulock({
          id: e.id
        })
        .then((res) => {
          if (res.data.errno == 0) {
            this.$message.success('驳回成功')
            this.getList()
          } else {
            this.$message.error('驳回失败')
          }
        })
        .catch((err) => {})
    },
    batchPass() {
      // 批量通过
      batchexamine()
        .then((res) => {})
        .catch((err) => {})
    },
    batchReject() {
      // 批量驳回
      batchnoexamine()
        .then((res) => {})
        .catch((err) => {})
    }
  }
}
</script>
<style scoped>
.operator-container {
  justify-content: space-between;
}
</style>
